window.onload=init_form;// JavaScript Document
function init_form(){
	for(var i=0;i<document.forms.length;i++){
		document.forms[i].onsubmit=function(){
			return validForm();
			}
		}	
	}
function validForm(){
	var allGood=true;
	var allTags=document.getElementsByName("*");
	for(var j=0;j<allTags.length;j++){
		if(!validTag(allTag[j])){
			allGood=false;
			}
		
		}
	return allGood;
	function validTag(thisTag){
		var outClass="";
		var allClasses=thisTag.className.split(" ");
		for(var i=0;i<allclasses.length;i++){
			outClass+=validBasedOnClass(allClasses[i])+" ";
			}
		thistag.className=outClass;
		if(outClass.indexOf("invalid")>-1){
			invalidlabel(thisTag.parentNode)
			thisTag.focus();
			if(thisTag.nodeName=="INPUT"){
				thisTag.select();
				}
				return false;
			}
			return true;
			function validbasedOnClass(thisClass){
				var classBack;
				switch(thisClass){
				case "":
				case "invalid":
				break;
				case "reqd":
					if(allGood && thisTag.value==""){
						classback="invalid";
					}
				classBack+=thisClass;
				break;
				case "radio":
				case "email":
				classBack+=thisClass;
				break;
				default:
					if(allGood && !crossCheck(thisTag,thisClass)){
						classBack="invalid";
					}
					classBack+=thisClass;
				}
				return classBack;
			}
			function crossCheck(inTag,otherFieldID){
				if(!document.getElementById(otherFieldID)){
					return false;
					}
					return (inTag.value=document.getElementById(otherFieldID).value);
			}
		}
}
